import * as api from "../../api/gw";
import axios from "axios";
//获取钱包余额
export const getWalletBalance = function () {
    let options = {
        url: window.api.customer_host + api.WALLET_BALANCE,
        method: "get",
        headers: {sessionId: localStorage.getItem("sessionId")}
    }
    return axios(options);
}

//通知后台使用钱包付款
export const walletPay = function (orderNo) {
    let opt = {
        url: window.api.trade_host + api.WALLET_NOTICE + `/${orderNo}`,
        method: "post",
        headers: {sessionId: localStorage.getItem("sessionId")}
    }
    return axios(opt);
}

//获取订单信息
export function getOrderInfo (orderNo, callback, errFn) {
    return new Promise((resolve, reject) => {
        let options = {
            method: "get",
            url: window.api.trade_host + api.gwOrderInfo + `/${orderNo}` + "?token=" + new Date().getTime(),
            headers: {sessionId: localStorage.getItem("sessionId")}
        }
        axios(options).then(data => {
            console.log("orderInfo", data);
            if (data.status === 200 && data.data.data.length > 0) {
                resolve({
                    status: data.status,
                    returnCode: data.data.returnCode,
                    ...data.data.data[0],
                });
            } else {
                // hideLoading();
                resolve({
                    status: data.status,
                    returnCode: data.data.returnCode,
                });
            }
        }).catch(err => {
            // hideLoading();
            resolve({
                status: "",
                returnCode: 0,
            });
            console.log(err);
        })
    });
}